<?php
    class Menu {

        private $ci;
        private $curid;

        const SHOW = 'style="display:block"';
        const HIDE = 'style="display:none"';

        function __construct() {
            $this->ci = &get_instance();
        }

        function getCurid() {
            return $this->curid;
        }

        function getNode($id) {
            $res = $this->ci->db->select('id, parent_id, title, is_default')->where('id', $id)->get('tree');
            if($res->num_rows() < 0) {
                return FALSE;
            }
            return $res->row_array();
        }

        function getChild($id) {
            $res = $this->ci->db->select('id, parent_id, title, is_default')->where('parent_id', $id)->get('tree');
            if($res->num_rows() < 0) {
                return FALSE;
            }

            return $res->result_array();
        }

        function getParent($id) {
            static $ret = array();
            $node = $this->getNode($id);
            if($node != FALSE) {
                $ret[] = $node;
                $this->getParent($node['parent_id']);
            }
            return array_reverse($ret);
        }

        function getTree() {
            $ret = '';
            $ret.='<ul>';
                $root = $this->getChild(1);
                foreach($root as $node) {
                    $ret .= '<li>'.$node['title'];
                }
            $ret.='</ul>';

            return $ret;
        }
    }
?>